<!DOCTYPE html>
<html>
    <head>
        <script>
         var num = 1;
         function changeImg(){
             var element = document.getElementById("img1");
             element.setAttribute("src",num+ ".jpg");
              num += 1;
              if (num >3) {
                  num=1;
              } else {
                  
              }
         }  
         setInterval(changeImg,1000);
        </script>

    </head>
    <body>
        
        <img src="1.jpg" alt="" id="img1">
       
    </body>
</html>